//
//  ChatRoomMyTableViewCell.m
//  RTMLibDemo
//
//  Created by admin on 2022/3/30.
//

#import "ChatRoomMyTableViewCell.h"
#import "Masonry/Masonry.h"
@implementation ChatRoomMyTableViewCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self initView];
    }
    return self;
}



-(void)setDic:(NSMutableDictionary *)dic{
    
    self.nameLable.text = [dic valueForKey:@"uid"];
    self.chatTextLable.text = [dic valueForKey:@"data"];
    CGSize textSize1 = [self.chatTextLable.text sizeWithAttributes:@{NSFontAttributeName:self.chatTextLable.font}];
    CGFloat height = [self.chatTextLable sizeThatFits:CGSizeMake([UIScreen mainScreen].bounds.size.width-130, MAXFLOAT) ].height;
    if (textSize1.width>[UIScreen mainScreen].bounds.size.width-130) {
        
        [self.chatTextLable mas_updateConstraints:^(MASConstraintMaker *make) {

            make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width-130);
            make.height.mas_equalTo(height);
            make.right.mas_equalTo(self.avatarImageView.mas_left).offset(-3);
           
        }];
        
    }else{
        
        [self.chatTextLable mas_updateConstraints:^(MASConstraintMaker *make) {
        
            make.right.mas_equalTo(self.avatarImageView.mas_left).offset(4);
            make.width.mas_equalTo(textSize1.width+10);
            make.height.mas_equalTo(height);
           
        }];
    }
 
 
}
-(void)initView{
    
    [self.contentView addSubview:self.avatarImageView];
    [self.avatarImageView addSubview:self.nameLable];
    [self.contentView addSubview:self.chatTextLable];
   
    [self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.mas_equalTo(self.contentView.mas_right).offset(-10);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(40, 40));
        
    }];

    [self.nameLable mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.mas_equalTo(self.avatarImageView.mas_centerX);
        make.centerY.mas_equalTo(self.avatarImageView.mas_centerY);
        make.left.mas_equalTo(self.avatarImageView.mas_left).offset(1);
        make.right.mas_equalTo(self.avatarImageView.mas_right).offset(-1);
        
    }];
    [self.chatTextLable mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.mas_equalTo(self.avatarImageView.mas_left).offset(4);
        make.centerY.mas_equalTo(self.avatarImageView.mas_centerY);
      
        
    }];



}
-(UILabel *)nameLable{
    
    if (_nameLable == nil) {
        _nameLable = [[UILabel alloc]init];
        _nameLable.font = [UIFont systemFontOfSize:14];
        _nameLable.textColor = [UIColor whiteColor];
        _nameLable.textAlignment = NSTextAlignmentCenter;
    }
    
    return _nameLable;
    
}
   
-(UILabel *)chatTextLable{
    
    if (_chatTextLable == nil) {
        _chatTextLable = [[UILabel alloc]init];
        _chatTextLable.font = [UIFont systemFontOfSize:16];
        _chatTextLable.textColor = [UIColor grayColor];
        _chatTextLable.numberOfLines = 0;
    }
    
    return _chatTextLable;
}
-(UIImageView *)avatarImageView{
    
    if (_avatarImageView == nil) {
        
        _avatarImageView = [[UIImageView alloc]init];
        _avatarImageView.backgroundColor = [UIColor colorWithRed:240/255.0 green:147/255.0 blue:142/225.0 alpha:1];
        _avatarImageView.layer.cornerRadius =20;
        _avatarImageView.clipsToBounds =YES;
    }
    return _avatarImageView;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
